package org.xiao;

import java.io.*;

public class BufferedReader1 {
    public static void main(String[] args) throws IOException {
        String fromS = "D:\\study\\IO\\IOstudy\\src\\main\\resources\\from";
        String toS = "D:\\study\\IO\\IOstudy\\src\\main\\resources\\to";
        long s = System.currentTimeMillis();
        for (int i = 0; i < 2; i++) {
            cpDir(new File(fromS), new File(toS));
        }
        long e = System.currentTimeMillis();
        System.out.println(e - s);
    }

    public static void cpDir(File from, File to) throws IOException {
        to.mkdirs();
        File[] files = from.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                cp(file.getPath(), to.getPath() + "/" + file.getName());
            } else {
                cpDir(file, new File(to.getPath() + "/" + file.getName()));
            }
        }
    }

    public static void readFile(String path) throws IOException {
        BufferedReader fis = new BufferedReader(new FileReader(path));
        String x;
        while ((x = fis.readLine()) != null) {
            System.out.print(x);
        }
        System.out.println();
        fis.close();
    }

    public static void in(String toS, String val) throws IOException {
        BufferedWriter fos = new BufferedWriter(new FileWriter(toS));
        fos.write(val.toCharArray());
        fos.close();
    }

    public static void cp(String fromS, String toS) throws IOException {
        BufferedWriter out = new BufferedWriter(new FileWriter(toS));
        BufferedReader in = new BufferedReader(new FileReader(fromS));
        String x;
        while ((x = in.readLine()) != null) {
            out.write(x);
            out.newLine();
        }
        out.close();
        in.close();
    }
}
